<?php

echo '<?xml version="1.0" encoding="UTF-8"?>'."\n";
?>
<graphml xmlns="http://graphml.graphdrawing.org/xmlns"  
	 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	 xsi:schemaLocation="http://graphml.graphdrawing.org/xmlns
		http://graphml.graphdrawing.org/xmlns/1.0/graphml.xsd">
	<graph id="G" edgedefault="directed">
<?php $done = array(); foreach($data as $node=>$subNodes) { $done[$node] = true;?>

		<node id="<?php echo $node ?>"/>
<?php  

foreach($subNodes as $subNode=>$weight) {
	if (false === isset($data[$subNode]) && false === isset($done[$subNode])) {
		$done[$subNode] = true;
?>
		<node id="<?php echo $subNode ?>"/>
<?php } ?>
		<edge source="<?php echo $node ?>" target="<?php echo $subNode ?>"/>
<?php }} ?>
	</graph>
</graphml>
